import { OlympicGuessAllData } from "../data/OlympicGuessAllData";
import { GCheckBox } from "../../../../../com/mui/controls/GCheckBox";
import { OlympicGuessDesc } from "../item/OlympicGuessDesc";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { OlympicBonusItem } from "../item/OlympicBonusItem";
import { Alert } from "../../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { MsgManager } from "../../../manager/MsgManager";
type int = number;
//class OlympicGuessMostGoldWin
    
    export  class OlympicGuessMostGoldWin /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._selectabled = false;
            this.initView();
            return;
        }

        public updateData(arg1: OlympicGuessAllData): void
        {
            var loc1=null;
            this._myData = arg1;
            if (this._boxes == null) 
            {
                return;
            }
            var loc2=0;
            while (loc2 < this._boxes.length) 
            {
                loc1 = this._boxes[loc2] as GCheckBox;
                if (loc1 != null) 
                {
                    loc1.selected = false;
                }
                ++loc2;
            }
            if (arg1.myTotalGoldNumAnswer != -1) 
            {
                this._mySelectedIndex = (arg1.myTotalGoldNumAnswer - 1);
                loc1 = this._boxes[this._mySelectedIndex] as GCheckBox;
                if (loc1 != null) 
                {
                    loc1.selected = true;
                }
            }
            if (arg1.canAnswerTotalGoldNum) 
            {
                if (arg1.isHaveAnsweredTotalGoldNum()) 
                {
                    this.setUnabledGuess();
                }
                else 
                {
                    this.setEnabledGuess();
                }
            }
            else 
            {
                this.setUnabledGuess();
            }
            return;
        }

        /* internal  */setEnabledGuess(): void
        {
            this._selectabled = true;
            return;
        }

        /* internal  */setUnabledGuess(): void
        {
            this._selectabled = false;
            return;
        }

        /* internal  */initView(): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc6=null;
            var loc7=0;
            var loc8=0;
            var loc9=null;
            this._desc = new OlympicGuessDesc();
            this.addChild(this._desc);
            loc1 = Language.getString(80003);
            this._desc.desc = loc1;
            loc3 = ObjCreate.createGTextField("", 298, this.ChooseLabelStartY, 60, 20, this);
            loc2 = loc3.defaultTextFormat;
            loc2.bold = true;
            loc3.defaultTextFormat = loc2;
            loc3.htmlText = Language.getString(80040);
            loc1 = Language.getString(80041);
            ObjCreate.createGTextField(loc1, 296, this.ChooseLabelStartY + this.VerticalDistance, 60, 20, this, loc2);
            loc1 = Language.getString(80042);
            ObjCreate.createGTextField(loc1, 289, this.ChooseLabelStartY + this.VerticalDistance * 2, 60, 20, this, loc2);
            loc1 = Language.getString(80043);
            ObjCreate.createGTextField(loc1, 282, this.ChooseLabelStartY + this.VerticalDistance * 3, 60, 20, this, loc2);
            this._boxes = [];
            var loc4=0;
            while (loc4 < 4) 
            {
                (loc6 = this.createCheckBox(349, this.ChooseLabelStartY + loc4 * this.VerticalDistance - 4)).addEventListener(flash.events.MouseEvent.CLICK, this.clickCheckBoxHandler);
                this._boxes.push(loc6);
                ++loc4;
            }
            ObjCreate.createBg(81, 213, 530, 50, this, ImagesConst.FightingStrgBg);
            loc1 = Language.getString(80044);
            loc3 = ObjCreate.createGTextField("", 166, 232, 120, 20, this);
            loc3.htmlText = loc1;
            var loc5=[14011633];
            loc4 = 0;
            while (loc4 < loc5.length) 
            {
                loc7 = loc5[loc4];
                loc8 = 1;
                (loc9 = new OlympicBonusItem(loc7, loc8)).x = this.BonusStartX + this.BonusGap * loc4;
                loc9.y = this.BonusStartY;
                this.addChild(loc9);
                ++loc4;
            }
            return;
        }

        /* internal  */clickCheckBoxHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var evt: Object /* flash.events.MouseEvent */;
            var target: GCheckBox;
            var answer: string;
            var choose: int;
            var i: int;
            var closeHandler: Function;
            var cb: GCheckBox;

            var loc1;
            answer = null;
            choose = 0;
            closeHandler = null;
            cb = null;
            evt = arg1;
            closeHandler = (arg1: int): void
            {
                var loc1=0;
                var loc2=null;
                if (arg1 != Alert.YES) 
                {
                    loc1 = 0;
                    while (loc1 < _boxes.length) 
                    {
                        loc2 = _boxes[loc1] as GCheckBox;
                        loc2.selected = false;
                        ++loc1;
                    }
                    return;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.OlympicSubmitMostGoldNumCountry, choose + 1));
                return;
            }
            target = evt.target as GCheckBox;
            if (this._myData == null) 
            {
                return;
            }
            if (!this._selectabled) 
            {
                this.takeUnselectableAction();
                return;
            }
            if (!target.selected) 
            {
                return;
            }
            choose = 0;
            i = 0;
            while (i < this._boxes.length) 
            {
                cb = this._boxes[i] as GCheckBox;
                if (cb != target) 
                {
                    cb.selected = false;
                }
                else 
                {
                    choose = i;
                }
                ++i;
            }
            answer = Language.getString(80040 + choose);
            Alert.show(Language.getStringByParam(80056, answer), null, Alert.YES | Alert.NO, null, closeHandler);
            return;
        }

        /* internal  */takeUnselectableAction(): void
        {
            var loc2=0;
            var loc3=null;
            var loc1=Language.getStringByParam(80045, Language.getString(80040 + this._mySelectedIndex));
            if (this._myData.isHaveAnsweredTotalGoldNum()) 
            {
                loc2 = 0;
                while (loc2 < this._boxes.length) 
                {
                    loc3 = this._boxes[loc2] as GCheckBox;
                    if (loc2 != this._mySelectedIndex) 
                    {
                        loc3.selected = false;
                    }
                    else 
                    {
                        loc3.selected = true;
                    }
                    ++loc2;
                }
            }
            else 
            {
                loc1 = Language.getString(80046);
            }
            MsgManager.showRollTipsMsg(loc1);
            return;
        }

        /* internal  */createCheckBox(arg1: number, arg2: number, arg3: string=""): GCheckBox
        {
            var loc1;
            (loc1 = new GCheckBox()).x = arg1;
            loc1.y = arg2;
            loc1.styleName = "GCheckBox";
            loc1.width = 50;
            loc1.label = arg3;
            this.addChild(loc1);
            return loc1;
        }

        /* internal */ /* const */ChooseLabelStartX: int=98;

        /* internal */ /* const */ChooseLabelStartY: int=73;

        /* internal */ /* const */VerticalDistance: int=36;

        /* internal */ /* const */BonusStartX: int=297;

        /* internal */ /* const */BonusGap: int=48;

        /* internal */ /* const */BonusStartY: int=221;

        /* internal */ /* var */_desc: OlympicGuessDesc;

        /* internal */ /* var */_boxes: Array<any>;

        /* internal */ /* var */_mySelectedIndex: int=-1;

        /* internal */ /* var */_selectabled: Boolean;

        /* internal */ /* var */_myData: OlympicGuessAllData;
    }
